﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using omsData;
namespace myomscl_web.Admin.UserControls
{
    public partial class ucEditUserType : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (OmsModelContainer context = new OmsModelContainer())
            {
                if (!context.UserTypes.Where(ut => ut.Name == txtNewUserTypeName.Text).Any())
                {
                    var newUserType = new UserType()
                    {
                        Name = txtNewUserTypeName.Text
                    };
                    

                    context.AddToUserTypes(newUserType);
                    context.SaveChanges();
                    AddedNewType(newUserType.Name);
                    
                }
            }
        }

        

        public delegate void OnAddedNewType(string newTypeName);        
        public event OnAddedNewType AddedNewType;
    }
}